/**
 * NumberAppearOnce.java created by zhangzhidong 
 * at 下午4:36:11 2016年10月11日
 */
package algorithm;

/**
 * @author zhangzhidong<br>
 * comment generated at 2016年10月11日下午4:36:11<br>
 * 
 */
public class NumberAppearOnce {
    public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) {
        get(array,num1,num2);
    }
    
    public void get(int arr[],int n1[],int n2[]){
        int holder = 0;
        for(int i =0;i<arr.length;i++){
        	holder ^= arr[i];    
        }
        if(holder == 0 ) return;
        int k = 0;
        while(holder>0){
            holder >>>= 1;
            k++;
        }
        //shift right k  bits then equal 0
       k--;
        int temp1[] = new int[arr.length];
        int index1 = 0;
        int temp2[] = new int[arr.length];
        int index2 = 0;
        for(int i = 0 ;i<arr.length;i++){
        	System.out.println((arr[i]>>>k) & 0x1);
            if(((arr[i]>>>k) & 0x1)== 0){
            	temp1[index1++] = arr[i];
            }else{
             	temp2[index2++] = arr[i];   
            }
            
        }
        holder = 0;
        for(int i = 0;i<temp1.length;i++){
			holder ^= temp1[i];
        }
        n1[0]=holder;
        holder = 0;
         for(int i = 0;i<temp2.length;i++){
			holder ^= temp2[i];
        }
        n2[0]=holder;
        
        
        
    }
    public static void main(String args[]){
    	int n1[] = new int[1];
    	int n2[] = new int[1];
    	new NumberAppearOnce().FindNumsAppearOnce(new int[]{2,4,3,6,3,2,5,5}, n1, n2);
    	
    	
    }
}
